<?php

/**
 * This is the model class for table "person".
 *
 * The followings are the available columns in table 'person':
 * @property integer $id
 * @property integer $departmentId
 * @property integer $titleID
 * @property string $name
 * @property string $mobile
 * @property string $Ext
 * @property string $short
 * @property string $skype
 * @property string $mail
 * @property string $memo
 *
 * The followings are the available model relations:
 * @property Department $department
 * @property Title $title
 */
class Person extends CActiveRecord {

    /**
     * Returns the static model of the specified AR class.
     * @param string $className active record class name.
     * @return Person the static model class
     */
    public static function model($className = __CLASS__) {
        return parent::model($className);
    }

    /**
     * @return string the associated database table name
     */
    public function tableName() {
        return 'person';
    }

    /**
     * @return array validation rules for model attributes.
     */
    public function rules() {
        // NOTE: you should only define rules for those attributes that
        // will receive user inputs.
        return array(
            array('departmentId, titleID,name', 'required'),
            array('departmentId, titleID', 'numerical', 'integerOnly' => true),
            array('name, skype, mail', 'length', 'max' => 25),
            array('english', 'length', 'max' => 30),
            array('image', 'length', 'max' => 255, 'on' => 'insert,update'),
            array('mobile', 'length', 'max' => 13),
            array('Ext', 'length', 'max' => 6),
            array('short', 'length', 'max' => 15),
            array('memo', 'length', 'max' => 35),
            array('image', 'file', 'types' => 'jpg, gif, png', 'maxSize' => 1024 * 1024 * 1, 'allowEmpty' => true, 'on' => 'update'),
            // The following rule is used by search().
            // Please remove those attributes that should not be searched.
            array('id, departmentId, titleID, name, mobile, Ext, short, skype, mail, english', 'safe', 'on' => 'search'),
        );
    }

    /**
     * @return array relational rules.
     */
    public function relations() {
        // NOTE: you may need to adjust the relation name and the related
        // class name for the relations automatically generated below.
        return array(
            'department' => array(self::BELONGS_TO, 'Department', 'departmentId'),
            'title' => array(self::BELONGS_TO, 'Title', 'titleID'),
        );
    }

    /**
     * @return array customized attribute labels (name=>label)
     */
    public function attributeLabels() {
        return array(
            'id' => 'ID',
            'departmentId' => '部门',
            'titleID' => '职称',
            'name' => '姓名',
            'english' => '英文名',
            'mobile' => '手机',
            'Ext' => '分机',
            'short' => '手机群号',
            'skype' => 'Skype',
            'mail' => '邮箱',
            'image' => '照片',
            'memo' => '备注',
        );
    }

    /**
     * Retrieves a list of models based on the current search/filter conditions.
     * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
     */
    public function search() {
        // Warning: Please modify the following code to remove attributes that
        // should not be searched.

        $criteria = new CDbCriteria;

        $criteria->compare('id', $this->id);
        $criteria->compare('departmentId', $this->departmentId);
        $criteria->compare('titleID', $this->titleID);
        $criteria->compare('name', $this->name, true);
        $criteria->compare('english', $this->english, true);
        $criteria->compare('mobile', $this->mobile, true);
        $criteria->compare('Ext', $this->Ext, true);
        $criteria->compare('short', $this->short, true);
        $criteria->compare('skype', $this->skype, true);
        $criteria->compare('mail', $this->mail, true);
        $criteria->compare('memo', $this->memo, true);

        return new CActiveDataProvider($this, array(
            'criteria' => $criteria,

        ));
    }

}
